package com.wbp.cms.client.common;

import java.util.ArrayList;
import java.util.List;

public class Page<T extends BaseDO> extends BaseDO {

	/**
	 * 
	 */
	private static final long serialVersionUID = 5277543297007773970L;
	// -- 分页参数 --//
	protected int pageNo = 1; // 当前页页号，注意页号是从1开始的
	protected int pageSize = 50; // 分页模型每页的大小

	protected int start = 0;

	// 查询数据库
	private int totalCount; // 总记录数
	private List<T> recordList = new ArrayList<T>(0); // 本页的数据列表

	private int currentPageCount ;// 当前分页的记录数
	
	// -- 构造函数 --//
	protected Page() {

	}
	
	public Page(List<T> recordList, int totalCount){
		this.totalCount = totalCount ;
		this.recordList = recordList ;
	}
	
	public Page(int pageNo,int pageSize ,List<T> recordList, int totalCount){
		this.pageNo = pageNo;
		this.pageSize = pageSize;
		this.totalCount = totalCount ;
		this.recordList = recordList ;
	}

	public Page(int pageNo, int pageSize) {
		this.pageNo = pageNo;
		this.pageSize = pageSize;
	}

	/**
	 * 获得当前页的页号,序号从1开始,默认为1.
	 */
	public int getPageNo() {
		return pageNo;
	}

	/**
	 * 设置当前页的页号,序号从1开始,低于1时自动调整为1.
	 */
	public void setPageNo(final int pageNo) {
		this.pageNo = pageNo;

		if (pageNo < 1) {
			this.pageNo = 1;
		}
	}

	/**
	 * 获得每页的记录数量,默认为100.
	 */
	public int getPageSize() {
		return pageSize;
	}

	/**
	 * 设置每页的记录数量,低于1时自动调整为100.
	 */
	public void setPageSize(final int pageSize) {
		this.pageSize = pageSize;

		if (pageSize < 1) {
			this.pageSize = 100;
		}
	}

	/**
	 * 根据pageNo和pageSize计算当前页第一条记录在总结果集中的位置.
	 */
	public Integer getFirst() {
		return (getPageNo() > 0 && getPageSize() > 0) ? ((getPageNo() - 1)
				* getPageSize() + 0) : 0;
	}

	public int getStartIndex() {
		return getFirst();
	}

	public int getStart() {
		return start;
	}

	public void setStart(int start) {
		this.start = start;
	}

	/**
	 * 根据pageNo和pageSize计算当前页最后一条记录在总结果集中的位置.
	 */
	public Integer getLast() {
		return (getFirst() + getPageSize() - 1);
	}

	public int getTotalCount() {
		return totalCount;
	}

	public void setTotalCount(int totalCount) {
		this.totalCount = totalCount;
	}

	public List<T> getRecordList() {
		return recordList;
	}

	public void setRecordList(List<T> recordList) {
		this.recordList = recordList;
	}

	public int getCurrentPageCount() {
		currentPageCount = this.recordList.size();
		return currentPageCount;
	}

	public void setCurrentPageCount(int currentPageCount) {
		this.currentPageCount = currentPageCount;
	}

}
